<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>

<jsp:include page="/includes/top.jsp"></jsp:include>
<div class="page-header">
	<h1></h1>
</div>
<!-- /.page-header -->
<div class="row">
	<div class="col-xs-12">
		<form class="form-horizontal" id="comForm">
			<div style="display: none">
				<input type="hidden" name="department.departmentId"
					value="${department.departmentId}" />
				<input type="hidden" name="department.companyId" id="hidcomid" />
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">部门名称:</label>
				<div class="col-sm-4">
					<div class="clearfix input-icon input-icon-right">
						<input type="text" class="form-control"
							value="${department.departmentName}"
							name="department.departmentName" placeholder="部门名称" />
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">上级部门:</label>
				<div class="col-sm-4">
					<div class="clearfix input-icon input-icon-right">
						<s:select cssClass="form-control" id="depart"
							name="department.parentDepartment" list="#dlist "
							listValue="departmentName" listKey="departmentId" headerKey="0"
							headerValue="请选择上级部门" value="department.parentDepartment"></s:select>
					</div>
				</div>
			</div>
			<div class="clearfix form-actions">
				<div class="col-md-offset-3 col-md-9">
					<button class="btn btn-info" id="save" type="button">
						<i class="icon-ok"></i> 保存
					</button>

					&nbsp; &nbsp; &nbsp;
					<button class="btn" type="reset" id="back">
						<i class="icon-undo"></i> 取消
					</button>
				</div>
			</div>
		</form>
	</div>
	<!-- /.col -->
</div>
<jsp:include page="/includes/bottom.jsp"></jsp:include>

<script type="text/javascript">
	$("#hidcomid").val(getQueryString("cid"));
	var did = getQueryString("department.departmentId");
	//添加
	function savafrom(url) {
		$("#save").click(function() {
			$("#comForm").bootstrapValidator("validate");
			if ($("#comForm").data("bootstrapValidator").isValid()) {
				var dataMap = $("#comForm").serializeArray();
				$.ajax({
					type : "post",
					url : url,
					data : dataMap,
					dataType : "json",
					success : function(data) {
						window.history.back();
					}
				});
			}
		});
	}

	$(document).ready(function() {
		$("#back").click(function() {
			window.history.back();
		});
		if (did != null && did != "") {
			savafrom("editdepart");
		} else {
			savafrom("adddepart");
		}
		$("#comForm").bootstrapValidator({
			feedbackIcons : {
				valid : 'icon-ok-sign',
				invalid : 'icon-remove-sign',
				validating : 'icon-refresh'
			},
			fields : {
				'department.departmentName' : {
					validators : {
						notEmpty : {
							message : '部门名称，不能为空！'
						}
					}
				}
			}
		});
	});
</script>
